#!/bin/sh

echo "********************************"
echo "OS type:"
uname
echo "********************************"

echo "********************************"
echo "OS version:"
uname -r | awk '{print substr($0,1,5)}'
echo "********************************"

echo "********************************"
echo "host name:"
hostname | awk '{print substr($0,1,9)}'
echo "********************************"


echo "********************************"
echo "disk info:"
if [ -e /dev/sda  ]; then
	echo "attempt to read /dev/sda"
	if [ -r /dev/sda ]; then
		echo "read /dev/sda SN:"
		lshw -class disk > diskinfo.tmp
		linenum=`grep -n '/dev/sda' diskinfo.tmp | head -n 1 | awk -F ':' '{print $1}'`
		sed -n ${linenum}',$p' diskinfo.tmp | grep 'serial' | head -n 1 | awk '{print substr($2, 1, 16)}'
		rm -f diskinfo.tmp
	else
		echo "/dev/sda: no read permission"
	fi
elif [ -e /dev/hda ]; then
	echo "attempt to read /dev/hda"
	if [ -r /dev/hda ]; then
		echo "read /dev/hda SN:"
		lshw -class disk > diskinfo.tmp
		linenum=`grep -n '/dev/hda' diskinfo.tmp | head -n 1 | awk -F ':' '{print $1}'`
		sed -n ${linenum}',$p' diskinfo.tmp | grep 'serial' | head -n 1 | awk '{print substr($2, 1, 16)}'
		rm -f diskinfo.tmp
	else
		echo "/dev/hda: no read permission"
	fi
else
	echo "none device find: /dev/sda;/dev/hda"
fi
echo "********************************"

echo "********************************"
echo "CPUID:"
if `dmidecode -t 4 > cpuinfo.tmp 2>/dev/null`; then
	grep 'ID' cpuinfo.tmp | head -n 1  | tr -d ' ' | awk -F ':' '{print substr($2, 1, 16)}'
else
	echo "can't read cpuinfo"
fi
rm -f cpuinfo.tmp
echo "********************************"

echo "********************************"
echo "BIOS SN:"
if `dmidecode -t 1 > biosinfo.tmp 2>/dev/null`; then
	grep 'Serial Number' biosinfo.tmp | head -n 1  | tr -d ' ' | awk -F ':' '{print substr($2, 1, 10)}'
else
	echo "can't read biosinfo"
fi
rm -f biosinfo.tmp
echo "********************************"

echo "********************************"
echo "network info:"
ip address > address.tmp
iplinenum=`grep -wn 'inet' address.tmp | grep -v '127.0.0.1' | tail -n 2 | awk -F ':' '{print $1}'`

count=1

for ipline in ${iplinenum}
do
	echo "network connection ${count}:"
	ipstr=`sed -n ${ipline}'p' address.tmp | awk '{print $2}' | awk -F '/' '{print $1}'`
	echo "ipaddr:${ipstr}"
	macstr=`sed -n '1,'${ipline}'p' address.tmp | grep 'link/ether' | tail -n 1 | awk '{print $2}' | tr -d ':'`
	echo "macaddr:${macstr}"
	echo ""
	count=$(($count+1))
done
rm -f address.tmp
echo "********************************"
